VFG.CommonImageryProvider = function(viewer, options) {
	this.viewer = viewer;
	this.options = options;
	this.id = options.id;
	this.name = options.name;
	this.code = options.code;
	this.type = options.type;
	this.imagery = options.thing;
	this.init();
}

//初始化
VFG.CommonImageryProvider.prototype.init = function() {
	let provider;
	if('terrain'==this.imagery.classify){
		provider=this.getTerrain();
		if(provider) this.ImageryProvider=this.viewer.terrainProvider = provider;
	}else{
		if('url'==this.imagery.serverType){
			provider=this.getUrlTemplateImageryProvider();
			if(provider) this.ImageryProvider=this.viewer.imageryLayers.addImageryProvider(provider);
		}
		else if('wmts'==this.imagery.serverType){
			provider=this.getWebMapTileServiceImageryProvider();
			if(provider) this.ImageryProvider=this.viewer.imageryLayers.addImageryProvider(provider);
		}
		else if('tms'==this.imagery.serverType){
			provider=this.getTileMapServiceImageryProvider();
			if(provider) this.ImageryProvider=this.viewer.imageryLayers.addImageryProvider(provider);
		}
	}
};

VFG.CommonImageryProvider.prototype.getUrlTemplateImageryProvider = function() {
	var parameter=eval('(' + this.imagery.options + ')') ;
	return new Cesium.UrlTemplateImageryProvider(parameter);
};

VFG.CommonImageryProvider.prototype.getTerrain = function() {
	var parameter=eval('(' + this.imagery.options + ')') ;
	return new Cesium.CesiumTerrainProvider(parameter)
};

VFG.CommonImageryProvider.prototype.getWebMapTileServiceImageryProvider = function() {
	return new Cesium.WebMapTileServiceImageryProvider(this.imagery.options)
};

VFG.CommonImageryProvider.prototype.getTileMapServiceImageryProvider = function() {
	return new Cesium.TileMapServiceImageryProvider(this.imagery.options)
};

VFG.CommonImageryProvider.prototype.destroy = function() {
	if(this.ImageryProvider){
		if('terrain'!=this.imagery.classify){
			this.viewer.imageryLayers.remove(this.ImageryProvider);
		}else{
			this.viewer.terrainProvider= new Cesium.EllipsoidTerrainProvider({});
		}
	}
	delete this.ImageryProvider
	delete this.options
    delete this.viewer
	return Cesium.destroyObject(this);
};
